package com.solweaver.greetings.utils;

import com.solweaver.greetings.dto.EventCreationRequest;
import com.solweaver.greetings.dto.EventCreationResponse;
import com.solweaver.greetings.dto.EventErrorEnum;
import com.solweaver.greetings.dto.GenericEnum;
import com.solweaver.greetings.dto.GetEventsByUserRequest;
import com.solweaver.greetings.dto.GetEventsByUserResponse;
import com.solweaver.greetings.dto.GetUsersByEventRequest;
import com.solweaver.greetings.dto.GetUsersByEventResponse;
import com.solweaver.greetings.dto.ModifyEventRequest;
import com.solweaver.greetings.dto.ModifyEventResponse;
import com.solweaver.greetings.dto.VideoRecordingRequest;
import com.solweaver.greetings.dto.VideoRecordingResponse;

public class ValidationUtils {

	public static void validateEventCreationRequest(EventCreationResponse eventCreationResponse, EventCreationRequest eventCreationRequest){
		
		if(eventCreationRequest.getChannel() == null){
			GenericUtils.buildErrorDetail(eventCreationResponse, GenericEnum.INVALID_CHANNEL);
		}
		
		if(eventCreationRequest.getCreatedByUser() == null || (eventCreationRequest.getCreatedByUser().getUserId() == null &&
				eventCreationRequest.getCreatedByUser().getEmailId() == null) ){
			GenericUtils.buildErrorDetail(eventCreationResponse, EventErrorEnum.FROM_USER_INVALID);
		}
		
		if(eventCreationRequest.getEventName() == null){
			GenericUtils.buildErrorDetail(eventCreationResponse, EventErrorEnum.INVALID_EVENT_NAME);
		}
		
		if(eventCreationRequest.getDescription() == null){
			GenericUtils.buildErrorDetail(eventCreationResponse, EventErrorEnum.INVALID_EVENT_DESCRIPTION);
		}
		
		//Date currentDate = Calendar.getInstance().getTime();
		
		/*if(eventCreationRequest.getEventDate() == null){
			GenericUtils.buildErrorDetail(eventCreationResponse, EventErrorEnum.INVALID_EVENT_DATE);
		}else{
			try{
				Date eventDate = eventCreationRequest.getEventDate();
				if(currentDate.after(eventDate)){
					GenericUtils.buildErrorDetail(eventCreationResponse, EventErrorEnum.INVALID_EVENT_DATE);
				}
			}catch(Exception exception){
				exception.printStackTrace();
				GenericUtils.buildErrorDetail(eventCreationResponse, EventErrorEnum.INVALID_EVENT_DATE);
			}
		}*/
		
		if(eventCreationResponse.getErrorDetailList() == null || eventCreationResponse.getErrorDetailList().size() == 0){
			GenericUtils.buildErrorDetail(eventCreationResponse, GenericEnum.Success);
		}
	}

	public static void validateGetEventsByUserRequest(GetEventsByUserRequest getEventsRequest,
			GetEventsByUserResponse getEventsResponse) {
		if(getEventsRequest.getChannel() == null){
			GenericUtils.buildErrorDetail(getEventsResponse, GenericEnum.INVALID_CHANNEL);
		}
		
		if(getEventsRequest.getEventStatus() == null){
			GenericUtils.buildErrorDetail(getEventsResponse, EventErrorEnum.EVENT_STATUS_IS_REQUIRED);
		}
		
		if(getEventsRequest.getUserId() == null){
			GenericUtils.buildErrorDetail(getEventsResponse, GenericEnum.INVALID_USER);
		}
		
		if(getEventsRequest.getUserEventTypeList() == null || getEventsRequest.getUserEventTypeList().size() <= 0){
			GenericUtils.buildErrorDetail(getEventsResponse, EventErrorEnum.USER_EVENT_TYPE_IS_REQUIRED);
		}
		
		if(getEventsResponse.getErrorDetailList() == null || getEventsResponse.getErrorDetailList().size() == 0){
			GenericUtils.buildErrorDetail(getEventsResponse, GenericEnum.Success);
		}
	}

	public static void validateRecordingRequest(
			VideoRecordingResponse videoRecordingResponse,
			VideoRecordingRequest videoRecordingRequest) {
		
		if(videoRecordingRequest.getChannel() == null){
			GenericUtils.buildErrorDetail(videoRecordingResponse, GenericEnum.INVALID_CHANNEL);
		}
		
		if((videoRecordingRequest.getUserEventId() == null) &&
				(videoRecordingRequest.getEventId() == null && videoRecordingRequest.getUserId() == null)){
			GenericUtils.buildErrorDetail(videoRecordingResponse, EventErrorEnum.USER_EVENT_DETAILS_ARE_REQUIRED);
		}
		
		if(videoRecordingRequest.getRecordingMode() == null ){
			GenericUtils.buildErrorDetail(videoRecordingResponse, EventErrorEnum.INVALID_RECORDING_MODE);
		}
	}

	public static void validateGetUsersByEventRequest(
			GetUsersByEventRequest getUsersByEventRequest,
			GetUsersByEventResponse getUsersByEventResponse) {
		if(getUsersByEventRequest.getChannel() == null){
			GenericUtils.buildErrorDetail(getUsersByEventResponse, GenericEnum.INVALID_CHANNEL);
		}
		
		if(getUsersByEventRequest.getEventId() == null){
			GenericUtils.buildErrorDetail(getUsersByEventResponse, EventErrorEnum.INVALID_EVENT_ID);
		}
		
		if(getUsersByEventResponse.getErrorDetailList() == null || getUsersByEventResponse.getErrorDetailList().size() == 0){
			GenericUtils.buildErrorDetail(getUsersByEventResponse, GenericEnum.Success);
		}
	}

	public static void validateModifyEventRequest(
			ModifyEventResponse modifyEventResponse,
			ModifyEventRequest modifyEventRequest) {
		if(modifyEventRequest.getChannel() == null){
			GenericUtils.buildErrorDetail(modifyEventResponse, GenericEnum.INVALID_CHANNEL);
		}
		
		if(modifyEventRequest.getEventId() == null){
			GenericUtils.buildErrorDetail(modifyEventResponse, EventErrorEnum.INVALID_EVENT_ID);
		}
		
		if(modifyEventResponse.getErrorDetailList() == null || modifyEventResponse.getErrorDetailList().size() == 0){
			GenericUtils.buildErrorDetail(modifyEventResponse, GenericEnum.Success);
		}
	}
	
}
